package com.quark.web.ui.field;

import com.quark.data.type.QuarkVariable;
import com.quark.framework.utility.QuarkLog;
import com.quark.framework.utility.QuarkUtilHtmlEscape;
import com.quark.web.ui.base.QuarkUiSetting;
import com.quark.web.ui.base.QuarkUiTextareaElement;

public class QuarkUiTextAreaField extends QuarkUiFieldBase {

	QuarkUiTextareaElement element = null;
	static Integer defaultCols = 150;
	static Integer defaultRows = 10;
 	public QuarkUiTextAreaField(String FieldName) { 
		super(FieldName, new QuarkUiTextareaElement(FieldName, FieldName, defaultCols, defaultRows, QuarkUiSetting.TEXTAREA_CLASS, ""));
		// TODO Auto-generated constructor stub
		element = (QuarkUiTextareaElement) elementBase;
		colspan = 2;
	}
 	
 	public String createField()
 	{
 		return element.createElement();
 	}
 	
 	public void clearField()
 	{
 		element.setInnerText("");
 	}

 	public boolean fillFieldWith(Object param)
 	//Accept String-parsable object
 	{
 		if(param == null)
 		{
 			QuarkLog.logError(getClass().getName(), " can't fill with null");
 			clearField();
 			return false;
 		}
 		
 		QuarkVariable var = new QuarkVariable(param, String.class);
 		element.setInnerText(var.toString());
 		return true;
 	}
 	
 	public Object processSubmitData(Object rawData)
 	{
 		if(rawData == null)
 			return "";
 		return QuarkUtilHtmlEscape.unescape(rawData.toString());
 	}
}
